package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CashierBill;
import cn.wolfcode.crm.domain.CashierBillitem;
import cn.wolfcode.crm.serivce.ICashierBillService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("cashier")
public class CashierController {
    @Autowired
    //引入账单
    private ICashierBillService cashierBillService;
    //引入出库service
    @RequestMapping("view")
    public String view() throws Exception {
        return "cashier";
    }

    @RequestMapping("listAll")
    @ResponseBody
    public PageResult listAll() throws Exception {
        PageResult pageResult = cashierBillService.selectAll();
        return pageResult;
    }
    //挂单的方法
    @RequestMapping("onAccount")
    @ResponseBody
    public JSONResult onAccount(CashierBill cashierBill) throws Exception {
        cashierBillService.onAccount(cashierBill);
        return  new JSONResult();
    }

    //付款的方法
    @RequestMapping("payAccount")
    @ResponseBody
    public JSONResult pay(CashierBill cashierBill) throws Exception {
        try {
            cashierBillService.pay(cashierBill);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark(e.getMessage());
        }
        return new JSONResult();
    }


    //取单的方法
    @RequestMapping("getAccount")
    @ResponseBody
    public List<CashierBillitem> getAccount(String cardNumber) throws Exception {
        //参数单会员卡号
        List<CashierBillitem> cashierBillitems = cashierBillService.selectByPrimaryKey(cardNumber);
        return cashierBillitems;
    }

}
